using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 对象池
/// </summary>
public class ObjectPool : MonoBehaviour
{
    //获取资源
    public GameObject Monster;
    private Stack<GameObject> monsterPool;
    private Stack<GameObject> activeMonsterList;


    void Start()
    {
        monsterPool = new Stack<GameObject>();//对象池
        activeMonsterList = new Stack<GameObject>();//活动对象列表
    }

    private GameObject GetMonster()
    {
        GameObject monsterGo = null;
        if (monsterPool.Count <= 0)
        {
            monsterGo = Instantiate(Monster);
        }
        else
        {
            monsterGo = monsterPool.Pop();
            monsterGo.SetActive(true);
        }
        activeMonsterList.Push(monsterGo);
        return monsterGo;
    }

    private void PushMonster(GameObject monsterGo)
    {
        monsterGo.transform.SetParent(transform);
        monsterGo.SetActive(false);
        monsterPool.Push(monsterGo);
    }
}
